<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /*  */
        .box{
            position: absolute;
            left: 0;
            width: 100px;
            height: 100px;
            background-color: #bfa;
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <script>
        //动画实现的核心原理:通过定时器 setInterval()不断移动盒子位置
        var box= document.querySelector('.box')
        //获取盒子位置
         box.offsetLeft 
        box.timer = setInterval(function(){
            if(box.offsetLeft >=400){
                clearInterval(box.timer)
            }else{
                box.style.left = box.offsetLeft + 1 +'px'
            }
            
        },10)
    </script>
</body>
</html>